class Article < ApplicationRecord

  validates :title, presence: true

  belongs_to :user

  has_many :modifications, dependent: :destroy

  after_save :create_version

  private

  def create_version
    if title_changed? or content_changed?
      self.modifications.create(title: title, content: content)
    end
  end

end
